﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace MugenInjection.Interface
{
    /// <summary>
    /// Specific collection for <see cref="IBinding"/>s.
    /// </summary>
    public interface IBindingCollection : IDisposableObject, IEnumerable<IBinding>
    {
        /// <summary>
        /// Gets the number of elements contained in the <see cref="IBindingCollection"/>.
        /// </summary>
        /// <returns>
        /// The number of elements contained in the <see cref="IBindingCollection"/>.
        /// </returns>
        int Count { get; }

        /// <summary>
        /// Gets a collection of all <see cref="IBindingBuilder"/> in current <see cref="IBindingCollection"/>.
        /// </summary>
        ReadOnlyCollection<IBindingBuilder> BindingBuilders { get; }

        /// <summary>
        /// Searches all the <see cref="IBinding"/> satisfying the specified <see cref="IBindingContext"/>.
        /// </summary>
        /// <param name="context">The specified <see cref="IBindingContext"/>.</param>
        /// <returns>An instances of <see cref="IBinding"/>.</returns>
        IEnumerable<IBinding> WhereCanResolve(IBindingContext context);

        /// <summary>
        /// Searches all the <see cref="IBinding"/> satisfying the specified <see cref="Type"/>.
        /// </summary>
        /// <param name="service">The specified <see cref="Type"/>.</param>
        /// <returns>An instances of <see cref="IBinding"/>.</returns>
        IList<IBinding> WhereServiceEqual(Type service);

        /// <summary>
        /// Adds the specified <see cref="IBinding"/>.
        /// </summary>
        /// <param name="binding">The specified binding.</param>
        void AddBinding(IBinding binding);

        /// <summary>
        /// Removes the specified <see cref="IBinding"/>.
        /// </summary>
        /// <param name="binding">The specified binding.</param>
        bool RemoveBinding(IBinding binding);

        /// <summary>
        /// Adds the specified <see cref="IBindingBuilder"/>.
        /// </summary>
        /// <param name="bindingBuilder">The specified binding builder.</param>
        void AddBindingBuilder(IBindingBuilder bindingBuilder);

        /// <summary>
        /// Removes the specified <see cref="IBindingBuilder"/>.
        /// </summary>
        /// <param name="bindingBuilder">The specified binding builder.</param>
        bool RemoveBindingBindingBuilder(IBindingBuilder bindingBuilder);

        /// <summary>
        /// Occurs after add specified <see cref="IBinding"/>.
        /// </summary>
        event Action<IBinding> AddedBinding;

        /// <summary>
        /// Occurs after remove specified <see cref="IBinding"/>.
        /// </summary>
        event Action<IBinding> RemovedBinding;

        /// <summary>
        /// Occurs after add specified <see cref="IBindingBuilder"/>.
        /// </summary>
        event Action<IBindingBuilder> AddedBindingBuilder;

        /// <summary>
        /// Occurs after remove specified <see cref="IBindingBuilder"/>.
        /// </summary>
        event Action<IBindingBuilder> RemovedBindingBuilder;
    }
}